package com.woniuxy.yuekeuser.dao;

import com.woniuxy.yuekeuser.info.UserInfo;
import com.woniuxy.yuekeuser.model.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Freedom
 * @since 2020-11-03
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from user where user_tel = #{tel}")
    User selectByUserTel(@Param("tel") String tel);

    @Select("select *  from  user t1 join user_role t2 " +
            "on t1.user_id = t2.user_id join role t3 " +
            "on t2.role_id = t3.role_id where " +
            "user_tel = #{userTel} and password = #{password} and t3.role_code != 'admin'")
    UserInfo selectByUserTelAndPasswordAndPassword(@Param("userTel") String userTel, @Param("password") String password);

    @Select("select * from  user join user_role on user.user_id = user_role.user_id join role " +
            "on user_role.role_id = role.role_id " +
            " where user_tel = #{tel}")
    UserInfo selectByTel(String tel);

    @Insert("insert into user_role(user_id,role_id) value(#{userId},1)")
    void insertRole(int userId);

    /**
     * 修改用户信息
     * @param user
     */
    @Update("update user set user_tel=#{userTel},password=#{password},name=#{name},email=#{email},age=#{age},head_portrait_address=#{headPortraitAddress} where user_id = #{userId}")
    void updatamessige(User user);

    @Select("select user_tel,password,name,email,age,gender,head_portrait_address from user where user_id = #{userId}")
    User findUserByUserId(int userId);
}
